/* main.c */

#include "app_inc.h"

int main(void)
{
    /* Initialize the board. */
    BSP_InitSystem();
    BSP_InitStdioUART(115200);
    BSP_InitLEDGPIO();
    
    printf("\r\nBlinky v1.4 Project.\r\n");

    /* Led. */
    GPIO_SetPinLogic(BSP_GPIO_LED3_PORT, BSP_GPIO_LED3_PIN, true);
    GPIO_SetPinDir(BSP_GPIO_LED3_PORT, BSP_GPIO_LED3_PIN, true);
    
    printf("Type anything into terminal to toggle the Led3\r\n");
    
    /* Enable the interrupt for UART0 Rx. */
    NVIC_EnableIRQ(UART0_RX_TX_IRQn);
    UART_SetIntEnabledOnRxBufferFull(UART0, true);
    
    while (1) /* Endless loop. */
    {
        __ASM("WFI");
    }
}

/* ISR for UART0 */
void UART0_RX_TX_IRQHandler(void)
{
    volatile uint8_t tmp8;
    /* ISR for RX. */
    if (UART_IsRxBufferFull(UART0))
    {
        tmp8 = UART_GetRxData(UART0); /* Read rx data to clear rx flag. */
        
        /* Toggle the Led3. */
        GPIO_TogglePinLogic(BSP_GPIO_LED3_PORT, BSP_GPIO_LED3_PIN);
    }
}

/* EOF. */

